// 先动态加载所有组件
const componentsMap = import.meta.glob('@/views/*/*/*.vue')
// 格式化路由
export const fomatRoute = (menus = [], faComName = '') => {
  const handFaCName = faComName ? '/' + faComName : ''
  let newList = menus.map((item) => {
    const result = {
      ...item,
      component:
        item.route + '' === '1'
          ? componentsMap[`/src/views${handFaCName}/${item.component}/${item.component}.vue`]
          : null,
      children: item?.children?.length > 0 ? fomatRoute(item.children, item.component) : [],
      path: item.route + '' === '1' ? `${handFaCName}/${item.component}` : '',
      componentName: item.component,
      meta: { ...item.meta, componentName: faComName || item.component },
      name: `/src/views${handFaCName}/${item.component}/${item.component}.vue`
    }
    return result
  })
  return newList
}
